package com.mmall.service.impl;

import com.google.common.collect.Maps;
import com.mmall.common.ServerResponse;
import com.mmall.dao.OrderMapper;
import com.mmall.dao.ProductMapper;
import com.mmall.dao.UserMapper;
import com.mmall.service.IStatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @ClassName: StatisticServiceImpl
 * @Title: mmall
 * @Package: com.mmall.service.impl
 * @Description:
 * @author: liuqingsong
 * @E-mail: lqs_email@163.com
 * @version: 创建时间: 2019/10/11 14:10
 */
@Service("iStatisticService")
public class StatisticServiceImpl implements IStatisticService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private ProductMapper productMapper;

    @Override
    public ServerResponse baseCount(){
        int userCount=userMapper.selectTotalUserCount();
        int productCount=productMapper.selectAllProductCount();
        int orderCount=orderMapper.selectAllOrderCount();
        if (userCount>=0&&productCount>=0&&orderCount>=0){
            Map<String,Integer> resultMap= Maps.newHashMap();
            resultMap.put("userCount",userCount);
            resultMap.put("productCount",productCount);
            resultMap.put("orderCount",orderCount);
            return ServerResponse.createBySuccess(resultMap);
        }
        return ServerResponse.createByErrorMessage("出错啦");
    }
}
